package cn.edu.sjtu.se.dslab.component.design;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * 
 * @author longshaohang
 * 
 */

@Entity
@Table(name = "design_pattern_instance")
public class DesignPatternInstance implements Serializable {

	private static final long serialVersionUID = -6571973980720756530L;

	private long id;
	private Date createTime;
	private String name;
	//private Set<DesignPatternPropertyInstance> propertyInstances;

	private DesignPattern designPattern;

	private DesignPatternComponent component;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@Column(nullable = false)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable = false, insertable = true, updatable = false, name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

//	@OneToOne(cascade = CascadeType.ALL)
	@OneToOne(cascade = CascadeType.REFRESH)
	@JoinColumn(name = "design_pattern_id", nullable = false)
	public DesignPattern getDesignPattern() {
		return designPattern;
	}

	public void setDesignPattern(DesignPattern designPattern) {
		this.designPattern = designPattern;
	}

	// map to "private DesignPatternInstance instance" in
	// DesignPatternPropertyInstance
//	@OneToMany(cascade = { CascadeType.ALL }, mappedBy = "instance")
//	public Set<DesignPatternPropertyInstance> getPropertyInstances() {
//		return propertyInstances;
//	}
//
//	public void setPropertyInstances(
//			Set<DesignPatternPropertyInstance> propertyInstances) {
//		this.propertyInstances = propertyInstances;
//	}

	@OneToOne(mappedBy = "instance")
	public DesignPatternComponent getComponent() {
		return component;
	}

	public void setComponent(DesignPatternComponent component) {
		this.component = component;
	}

}
